<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="f()" >
<div>结果：<span></span></div>


<script>
  function f(){
    let x = document.querySelector("#i1");
    let result = document.querySelector("span");
    if (isNaN(x.value)){
      result.innerText = "输入错误！";
      return;
    }
    //parseFloat()将字符串转成整数或小数
    result.innerText = parseFloat(x.value) + parseFloat(x.value);
  }
</script>
</body>
</html>